﻿using Application.Allot_dService;
using Application.Allot_hService;
using Domain.Entity;
using Domain.Entity.tr;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace WMSManage.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class Allot_hController : ControllerBase
    {
        public readonly IAllot_hService allot_hService;
        public Allot_hController(IAllot_hService allot_hService)
        {
            this.allot_hService = allot_hService;
        }

        /// <summary>
        /// 条件查
        /// </summary>
        /// <param name="CurrentPage"></param>
        /// <param name="al_code"></param>
        /// <param name="al_status"></param>
        /// <param name="instockoutstock_status"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public async Task<FenYe<Allot_h>> GetFenYe(int CurrentPage, string? al_code, int? al_status, int? instockoutstock_status, string? startTime, string? endTime)
        {
            FenYe<Allot_h> fenYe = new FenYe<Allot_h>()
            {
                CurrentPage = CurrentPage,
            };
            return await allot_hService.GetFenYe(fenYe, al_code, al_status, instockoutstock_status, startTime, endTime);
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPut]
        public async Task<int> GetDelete(int id)
        {
            return await allot_hService.GetDelete(id);
        }

        /// <summary>
        /// 审核
        /// </summary>
        /// <param name="al_id"></param>
        /// <param name="al_status"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPut]
        public async Task<int> GetAudit(int al_id, int al_status, string user)
        {
            return await allot_hService.GetAudit(al_id, al_status, user);
        }

        /// <summary>
        /// 高级查询
        /// </summary>
        /// <param name="CurrentPage"></param>
        /// <param name="al_code"></param>
        /// <param name="al_status"></param>
        /// <param name="instock_status"></param>
        /// <param name="outstock_status"></param>
        /// <param name="requesttransferstartTime"></param>
        /// <param name="requesttransferendTime"></param>
        /// <param name="al_type"></param>
        /// <param name="out_wh_id"></param>
        /// <param name="in_wh_id"></param>
        /// <param name="al_user"></param>
        /// <param name="createstartTime"></param>
        /// <param name="createendTime"></param>
        /// <param name="auditstartTime"></param>
        /// <param name="auditendTime"></param>
        /// <param name="approver_name"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<FenYe<Allot_h>> GetSeniorFenYe(int CurrentPage,string? al_code,int? al_status, [FromQuery] int[]? instock_status, [FromQuery] int[]? outstock_status, string? requesttransferstartTime, string? requesttransferendTime, string? al_type, int? out_wh_id, int? in_wh_id, string? al_user, string? create_name, string? createstartTime, string? createendTime, string? auditstartTime, string? auditendTime, string? approver_name)
        {
            FenYe<Allot_h> fenYe = new FenYe<Allot_h>()
            {
                CurrentPage = CurrentPage,
            };
            return await allot_hService.GetSeniorFenYe(fenYe, al_code, al_status, instock_status, outstock_status, requesttransferstartTime, requesttransferendTime, al_type, out_wh_id, in_wh_id, al_user, create_name, createstartTime, createendTime, auditstartTime, auditendTime, approver_name);
        }

        /// <summary>
        /// 调拨添加
        /// </summary>
        /// <param name="addAllotDto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> AddAudit(AddAllotDto addAllotDto)
        {
            int a = await allot_hService.AddAudit(addAllotDto);
            return a;
        }

        /// <summary>
        /// ID查
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Allot_h> GetId(int id)
        {
            return await allot_hService.GetId(id);
        }

        /// <summary>
        /// 调拨修改
        /// </summary>
        /// <param name="updateAllotDto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> UpdateAudit(UpdateAllotDto updateAllotDto)
        {
            int a = await allot_hService.UpdateAudit(updateAllotDto);
            return a;
        }

        /// <summary>
        /// 调拨汇总信息
        /// </summary>
        /// <param name="proc_code"></param>
        /// <param name="al_code"></param>
        /// <param name="al_type"></param>
        /// <param name="header_create_by"></param>
        /// <param name="type_id"></param>
        /// <param name="proc_primary_unit"></param>
        /// <param name="al_user"></param>
        /// <param name="out_wh_id"></param>
        /// <param name="in_wh_id"></param>
        /// <param name="instock_status"></param>
        /// <param name="outstock_status"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <param name="createstartTime"></param>
        /// <param name="createendTime"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<AllotTotals> Gettotal(string? proc_code, string? al_code, string? al_type, string? header_create_by, int? type_id, string? proc_primary_unit, string? al_user, int? out_wh_id, int? in_wh_id, [FromQuery] int[] instock_status, [FromQuery] int[] outstock_status, string? startTime, string? endTime, string? createstartTime, string? createendTime)
        {
            return await allot_hService.Gettotal(proc_code, al_code, al_type, header_create_by, type_id, proc_primary_unit, al_user, out_wh_id, in_wh_id, instock_status, outstock_status, startTime, endTime, createstartTime, createendTime); ;
        }


        /// <summary>
        /// 查询要出入库的调拨单
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<Allot_h>> GetAllot_Hs(string name)
        {
            return await allot_hService.GetAllot_Hs(name);
        }


        /// <summary>
        /// 查询货品调拨记录
        /// </summary>
        /// <param name="procid"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<Allot_h>> GetByPid(int procid)
        {
            return await allot_hService.GetByPid(procid);
        }
    }
}
